﻿<%@ Page Title="Cập nhật hợp đồng" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Edit.aspx.cs" Inherits="QuanLyHopDong.Web.HopDong.Edit" %>

<%@ Import Namespace="Resources" %>

<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%=GlobalStrings.Edit %> hợp đồng</h2>
    <p>
        <span class="failureNotification">
        <strong><asp:Literal ID="ltrThiCongXong" runat="server"></asp:Literal></strong></span>
    </p>
    <span class="failureNotification">
        <asp:Literal ID="lblErrorMessage" runat="server"></asp:Literal></span>

    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">Thông tin chung</a></li>
            <li><a href="#tabs-2">File hợp đồng</a></li>
            <%--<li><a href="#tabs-2">Khối lượng hợp đồng</a></li>
            <li><a href="#tabs-3">Quyết toán</a></li>--%>
        </ul>
        <div id="tabs-1">
            <p>
                <label>Nhân viên xử lý:</label>
                <asp:DropDownList ID="ddlEmployees" runat="server"></asp:DropDownList>
            </p>
            <table>
                <tr>
                    <td style="vertical-align: top;">
                        <div style="margin-right: 50px; vertical-align: top;">
                            <p>
                                <label>Số HĐ:</label>
                                <asp:TextBox ID="txtSoHopDong" runat="server" CssClass="textEntry name"></asp:TextBox>
                            </p>
                            <p>
                                <label>Tên HĐ:</label>
                                <asp:TextBox ID="txtTenHopDong" runat="server" CssClass="textEntry name"></asp:TextBox>
                            </p>
                            <p>
                                <label>Ngày ký:</label>
                                <asp:TextBox ID="txtNgayKy" runat="server" CssClass="textEntry date datepicker"></asp:TextBox>
                            </p>
                            <p>
                                <label>Ngày bắt đầu thi công:</label>
                                <asp:TextBox ID="txtNgayBatDauThiCong" runat="server" CssClass="textEntry date datepicker"></asp:TextBox>
                            </p>
                            <p>
                                <label>Ngày kết thúc thi công:</label>
                                <asp:TextBox ID="txtNgayKetThucThiCong" runat="server" CssClass="textEntry date datepicker"></asp:TextBox>
                            </p>
                            <p>
                                <label>Giá trị hợp đồng chưa VAT:</label>
                                <asp:TextBox ID="txtGiaTriHopDongChuaVAT" runat="server" CssClass="textEntry date validate[number]"></asp:TextBox>
                            </p>
                            <p>
                                <label>Tổng giá trị hợp đồng:</label>
                                <asp:TextBox ID="txtTongGiaTriHopDong" runat="server" CssClass="textEntry date validate[number]"></asp:TextBox>
                            </p>
                            <p>
                                <label>Tình trạng hợp đồng:</label>
                                <asp:DropDownList ID="ddlTrangThaiHopDong" runat="server">
                                    <asp:ListItem Value="1">Chưa ký hợp đồng</asp:ListItem>
                                    <asp:ListItem Value="2">Đã ký, đang thi công</asp:ListItem>
                                    <asp:ListItem Value="3">Đang hoàn công</asp:ListItem>
                                    <asp:ListItem Value="4">Đang quyết toán</asp:ListItem>
                                    <asp:ListItem Value="5">Hoàn thiện</asp:ListItem>
                                </asp:DropDownList>
                            </p>
                            <p>
                                <label>Ngày hoàn thiện:</label>
                                <asp:TextBox ID="txtNgayHoanThien" runat="server" CssClass="textEntry date datepicker"></asp:TextBox>
                            </p>
                        </div>
                    </td>
                    <td style="vertical-align: top;">
                        <div style="vertical-align: top;">
                            <p>
                                <label>Đơn vị:</label>
                                <asp:TextBox ID="txtTenDonVi" runat="server" CssClass="textEntry name validate[required]"></asp:TextBox>
                            </p>
                            <p>
                                <label>Loại dự án:</label>
                                <asp:TextBox ID="txtLoaiDuAn" runat="server" CssClass="textEntry name"></asp:TextBox>
                            </p>
                            <p>
                                <label>Giá trị vật tư:</label>
                                <asp:TextBox ID="txtGiaTriVatTu" runat="server" CssClass="textEntry date validate[number]"></asp:TextBox>
                            </p>
                            <p>
                                <label>Giá trị nhân công:</label>
                                <asp:TextBox ID="txtGiaTriNhanCong" runat="server" CssClass="textEntry date validate[number]"></asp:TextBox>
                            </p>
                            <p>
                                <label>Chi phí khác:</label>
                                <asp:TextBox ID="txtChiPhiKhac" runat="server" CssClass="textEntry date validate[number]"></asp:TextBox>
                            </p>
                            <p>
                                <label>VAT:</label>
                                <asp:TextBox ID="txtVat" runat="server" CssClass="textEntry date validate[number]"></asp:TextBox>
                            </p>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div id="tabs-2">
            <div id="FileList"></div>
            <p>
                <label>File hợp đồng:</label>
                <asp:FileUpload ID="fileHopDong" runat="server" /><br/>
                <asp:FileUpload ID="fileHopDong2" runat="server" /><br/>
                <asp:FileUpload ID="fileHopDong3" runat="server" /><br/>
                <asp:FileUpload ID="fileHopDong4" runat="server" />
            </p>
        </div>
    </div>
    
    <p>
        <asp:Button ID="btnSave" runat="server" Text="<%$ Resources:GlobalStrings, Save %>"
            OnClick="btnSave_Click" />
        <input type="button" value="Khối lượng" onclick="NhapKhoiLuong();"/>
        <input type="button" value="Quyết toán" onclick="NhapQuyetToan();"/>
        <input id="btnCancel" type="button" value="<%=GlobalStrings.Cancel %>"
            onclick="javascript: window.location = 'List.aspx';" />
    </p>

    <script type="text/javascript">
        var _hopDongId = <%=Request.Params["id"] %>;
        $(function () {
            
            // init tabs
            $("#tabs").tabs();
            
            $(window.theForm).validationEngine();

            $("#<%=txtNgayKy.ClientID %>").calendar({ timeSeparators: null });
            $("#<%=txtNgayBatDauThiCong.ClientID %>").calendar({ timeSeparators: null });
            $("#<%=txtNgayKetThucThiCong.ClientID %>").calendar({ timeSeparators: null });
            $("#<%=txtNgayHoanThien.ClientID %>").calendar({ timeSeparators: null });
            <%--$("#<%=txtNgayQuyetToan.ClientID %>").calendar({ timeSeparators: null });--%>
            
            $("#<%=txtTenDonVi.ClientID %>").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "/DanhMuc/DonVi/Default.aspx/SearchDonVis",
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json; charset=utf-8",
                        data: JSON.stringify({
                            term: extractLast(request.term)
                        }),
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.value,
                                    value: item.value
                                };
                            }));
                        }
                    });
                }
            });

            //LoadKhoiLuong();
            LoadFileList();
        });

        function LoadFileList() {
            $("#FileList").jtable({
                actions: {
                    listAction: 'Edit.aspx/FileList',
                    deleteAction: 'Edit.aspx/FileDelete'
                },
                fields: {
                    Id: {
                        title: 'STT',
                        key: true,
                        create: false,
                        edit: false,
                        width: '2%',
                        list: false
                    },
                    FileHopDong: {
                        title: 'File',
                        display: function(data) {
                            return '<a target="_blank" href="/Files/HopDong/' + _hopDongId + '/' + data.record.FileHopDong + '">' + data.record.FileHopDong + '</a>';
                        }
                    }
                }
            });

            $('#FileList').jtable(
                'load',
                { hopDongId: _hopDongId }
            );
        }

        function LoadKhoiLuong() {
            $("#KhoiLuongList").jtable({
                actions: {
                    listAction: 'KhoiLuong.aspx/KhoiLuongList',
                    deleteAction: 'KhoiLuong.aspx/KhoiLuongDelete'
                },
                fields: {
                    Id: {
                        title: 'STT',
                        key: true,
                        create: false,
                        edit: false,
                        width: '2%',
                        list: false
                    },
                    TenDonVi: { title: 'Đơn vị ký HĐ' },
                    SoHopDong: { title: "Số HĐ" },
                    LoaiDuAn: { title: "Loại dự án" },
                    MaTuyen: { title: "Mã tuyến" },
                    TinhTrangThiCong: { title: "Tiến độ thi công" },
                    GhiChu: { title: "Ghi chú" },
                    TinhTrangVatTu: { title: "Nhận vật tư A" },
                    DiemDau: { title: "Điểm đầu" },
                    DiemCuoi: { title: "Điểm cuối" },
                    ChieuDaiTuyen: { title: "Chiều dài tuyến" },
                    TenLoaiCap: { title: "Loại cáp" },
                    Edit: {
                        title: '',
                        width: '1%',
                        display: function(data) {
                            return '<input title="<%=GlobalStrings.Edit %>" class="jtable-command-button jtable-edit-command-button" onclick="javascript:window.location=\'KhoiLuongEdit.aspx?id=' + data.record.Id + '&hopDongId=<%=Request.Params["id"] %>' + '\';" />';
                        },
                        sorting: false
                    }
                }
            });

            $('#KhoiLuongList').jtable(
                'load',
                { hopDongId: _hopDongId }
            );
        }

        function split(val) {
            return val.split(/,\s*/);
        }

        function extractLast(term) {
            return split(term).pop();
        }

        function NhapKhoiLuong() {
            window.location = 'KhoiLuong.aspx?hopDongId=' + _hopDongId;
        }

        function NhapQuyetToan() {
            window.location = 'QuyetToan.aspx?hopDongId=' + _hopDongId;
        }
    </script>
</asp:Content>
